# encoding: utf-8
""" 
@version: v1.0 
@author: autumner 
@license: Apache Licence  
@contact: 18322313385@163.com 
@site:  https://gitee.com/autumner/pythoncookbook
@software: PyCharm 
@file: xmlrpc_calendar_server.py 
@time: 2019/7/22 下午4:24
"""

"""
创建xmlrpc版的日历，服务端
"""
import calendar, string
from xmlrpc.server import SimpleXMLRPCServer

class Calendar:

    def getMonth(self, year, month):
        if (type(year) is type("")):
            if (year.isdigit()):
                year = string.atoi(year)
            else:
                return "error, the argv must be number"
        if (type(month) is type("")):
            if (month.isdigit()):
                month = string.atoi(month)
            else:
                return "error, the argv must be number"
        return calendar.month(year, month)

    def getYear(self, year):
        if (type(year) is type("")):
            if (year.isdigit()):
                year = string.atoi(year)
            else:
                return "error, the argv must be number"
        return calendar.calendar(year)

    def getDict(self):
        dict = {'1': '1', '2': '2', '3': '3'}
        return dict


calendar_object = Calendar()
server = SimpleXMLRPCServer(('', 8888))
server.register_instance(calendar_object)
print("Listening on port 8888")
server.serve_forever()
